<include file="public@meta" />

<body>
<div class="layui-fluid">
    <div class="layui-card-body">
        <form method="post" action="{:url('editItem')}" class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">标题<span class="form-required">*</span></label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="slide[title]" value="{$item.title}"
                           lay-verify="required" lay-verType="tips" placeholder="图片标题">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">链接<span class="form-required">*</span></label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="slide[url]" value="{$item.url}"
                           lay-verify="required|url" lay-verType="tips" placeholder="图片链接">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图片<span class="form-required">*</span></label>
                <div class="layui-input-block">
                    <a id="btn-thumb">
                        <empty name="item.thumb">
                            <img src="__STATIC__/images/default-thumb.png" id="thumb-preview" height="135"
                                 style="cursor: pointer"/>
                            <else/>
                            <img src="{:get_image_url($item['thumb'])}" id="thumb-preview" height="135"
                                 style="cursor: pointer"/>
                        </empty>
                    </a>
                    <div id="tips-thumb"></div>
                    <input type="hidden" name="slide[thumb]" id="input-thumb" value="{$item.thumb}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-block">
                            <textarea class="layui-textarea" name="slide[desc]"
                                      placeholder="输入描述">{$item.desc}</textarea>
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <input type="hidden" name="slide[slide_id]" value="{$item.slide_id}">
                <input type="hidden" name="slide[id]" value="{$item.id}">
                <input type="button" lay-submit lay-filter="layui-btn-form-submit" id="layui-btn-form-submit" value="确认添加">
                <input type="button" lay-submit lay-filter="layui-btn-form-edit" id="layui-btn-form-edit" value="确认编辑">
            </div>
        </form>
    </div>
</div>

<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        layCenter: 'lib/layCenter', //主入口模块
    }).use(['index', 'form','layCenter','common','upload'], function(){
        var $ = layui.$,
            form = layui.form,
            layCenter = layui.layCenter,
            upload = layui.upload,
            common = layui.common;
        //监听提交
        form.on('submit(layui-btn-form-submit)', function(data){
            layCenter.FormSubmit("{:url('editItem')}",data.field,true);
        });

        upload.render({
            elem: '#btn-thumb',
            url: "{:url('api/asset/fileUpload')}",
            size: 2000,
            exts: 'jpg|png|bmp|jpeg',
            data: {path: 'slide'},
            before: function (obj) {
                obj.preview(function (index, file, result) {
                    $('#thumb-preview').attr('src', result); //图片链接（base64）
                });
            },
            done: function (res) {
                console.log(res)
                if (res.code == 0) {
                    return layer.msg(res.message);
                }
                $('#input-thumb').val(res.filepath);
            }
        });
    });
</script>
</body>
</html>